package cn.wuxing.mediation.web.controller.contradiction;

import cn.wuxing.mediation.common.core.controller.BaseController;
import cn.wuxing.mediation.common.core.domain.AjaxResult;
import cn.wuxing.mediation.common.core.page.PageDomain;
import cn.wuxing.mediation.common.core.page.TableSupport;
import cn.wuxing.mediation.common.utils.poi.ExcelUtil;
import cn.wuxing.mediation.system.domain.*;
import cn.wuxing.mediation.system.service.IQrlsbjStgDscHuzBiz029SjztjDfWxqService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/human")
public class HumanResourcesController extends BaseController {

    @Resource
    private IQrlsbjStgDscHuzBiz029SjztjDfWxqService qrlsbjStgDscHuzBiz029SjztjDfWxqService;

    @GetMapping("list")
    public AjaxResult list(HumanReqVo req) {
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        req.setCurrentPage((pageNum - 1) * pageSize);
        req.setPageSize(pageSize);

        List<HumanRespVo> humanRespVos =
                qrlsbjStgDscHuzBiz029SjztjDfWxqService.selectQrlsbjStgDscHuzBiz029SjztjDfWxqList(req);
        Long total=qrlsbjStgDscHuzBiz029SjztjDfWxqService.selectCount();

        return AjaxResult.successPage(humanRespVos,total);
    }

    @PostMapping("/export")
    public void export(HttpServletResponse response, HumanReqVo req)
    {
        if(req.getIds()==null||req.getIds().size()==0){//如果没勾选,就导出当前分页
            PageDomain pageDomain = TableSupport.buildPageRequest();
            Integer pageNum = pageDomain.getPageNum();
            Integer pageSize = pageDomain.getPageSize();
            req.setCurrentPage((pageNum-1)*pageSize);
            req.setPageSize(pageSize);
        }
        List<QrlsbjStgDscHuzBiz029SjztjDfWxq> qrlsbjStgDscHuzBiz029SjztjDfWxqs =
                qrlsbjStgDscHuzBiz029SjztjDfWxqService.selectQrlsbjStgDscHuzBiz029SjztjDfWxqListExpoet(req);
        ExcelUtil<QrlsbjStgDscHuzBiz029SjztjDfWxq> util = new ExcelUtil<QrlsbjStgDscHuzBiz029SjztjDfWxq>(QrlsbjStgDscHuzBiz029SjztjDfWxq.class);
        util.exportExcel(response, qrlsbjStgDscHuzBiz029SjztjDfWxqs, "人社平台数据");
    }
}
